package com.qf.business.utils;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
public class PinyinUtils {

    public static String str2Pinyin(String str){
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

        try {
            String pinyin = PinyinHelper.toHanYuPinyinString(str, format);
            return pinyin;
        } catch (BadHanyuPinyinOutputFormatCombination e) {
            e.printStackTrace();
            return null;
        }
    }

//    public static void main(String[] args) throws BadHanyuPinyinOutputFormatCombination {
//
//        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
//        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
//
//        String pinyin = PinyinHelper.toHanYuPinyinString("白@日#_abss依123123山尽", format);
//        System.out.println(pinyin);
//    }
}
